package cn.edu.nuc.ssm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.ssm.controller.page.PageControl;
import cn.edu.nuc.ssm.controller.page.Pager;
import cn.edu.nuc.ssm.controller.page.Pc;
import cn.edu.nuc.ssm.dao.ScreensMapper;
import cn.edu.nuc.ssm.domain.Screens;
import cn.edu.nuc.ssm.service.interfaces.ScreenService;
@Service
public class ScreenServiceImpl implements ScreenService{
    @Autowired
	private ScreensMapper mapper;
  //添加一个影厅
	@Override
	public int insert(Screens screens) {
		return mapper.insert(screens);
	}
	//后台分页显示影厅信息
	@Override
	public Pager<Screens> pageList(String screensname, int current) {
		PageControl pc = new PageControl();
		Integer currindex = 1;
		if(current != 0){
			currindex = current;
		}
		pc.setCurrentindex(currindex);
		
		//查询总记录数。(如果带有名字，则查询改名字的总记录数。(模糊查询)
		int count = mapper.count("%"+screensname+"%");
		pc.setRscount(count);
		//初始化分页参数。
		pc = Pc.dealpage(pc);
		//查询具体内容
		List<Screens> screens = mapper.selectScreens("%"+screensname+"%",(pc.getCurrentindex()-1)*pc.getPagesize(),
				pc.getCurrentindex()*pc.getPagesize());
		Pager<Screens> pager = new Pager<Screens>();
		pager.setList(screens);
		pager.setPagectrl(pc);
		return pager;
	}
	//通过影片类型id查询影片类型信息
	@Override
	public Screens selectByScreenid(Integer screenid) {
		return mapper.selectByPrimaryKey(screenid);
	}
	//更新影片类型信息(有选择)
	@Override
	public int updateByPrimaryKey(Screens screens) {
		return mapper.updateByPrimaryKeySelective(screens);
	}
	//通过主键删除单个影厅信息。
	@Override
	public int deleteByPrimaryKey(Integer screenid) {
		return mapper.deleteByPrimaryKey(screenid);
	}
	//通过影城id查询所有影厅
	@Override
	public List<Screens> selectByScreenid2(Integer fcid) {
		return mapper.selectByPrimaryKey2(fcid);
	}

}
